//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.IO;
using OpenLS.Core.Serialization;

namespace OpenLS.UI
{
    public class RecentlyUsedDocument: IComparable, IOfficeXmlSerializable
    {
        public RecentlyUsedDocument()
        {

        }
        public RecentlyUsedDocument(string fullName)
        {
            _fullName = fullName;

        }
        private DateTime _date = DateTime.Now;

        public DateTime Date
        {
            get { return _date; }
            set { _date = value; }
        }
	
        private string _fullName;

        public string FullName
        {
            get { return _fullName; }
            set { _fullName = value; }
        }
        public string Name
        {
            get
            {
                return Path.GetFileName(_fullName);
            }
        }
        private bool _locked;

        public bool IsLocked
        {
            get { return _locked; }
            set { _locked = value; }
        }


        #region IComparable Members

        public int CompareTo(object obj)
        {
            RecentlyUsedDocument other = obj as RecentlyUsedDocument;
            if (other ==null)
                return 0;
            return Date.CompareTo(other.Date);
        }

        #endregion

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read("document"))
            {
                FullName = c.GetString("FullName");
                IsLocked = c.GetBoolean("IsLocked");
                Date = c.GetDate("Date");
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("document"))
            {
                c.SetString("FullName", FullName);
                c.SetBoolean("IsLocked", IsLocked);
                c.SetDate("Date", Date);
            }
        }

        #endregion
    }
}
